﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ISMv1.Controls
{
    /// <summary>
    /// Interaction logic for MainMenu.xaml
    /// </summary>
    public partial class MainMenu : UserControl
    {
        private MainWindow mainWindow { get; set; }

        private bool _newCanExecute, _openCanExecute, _saveCanExecute, _saveAsCanExecute, _copyCanExecute, _pasteCanExecute, _cutCanExecute, _deleteCanExecute, _exportCanExecute, _workshopCanExecute, _printCanExecute, _printerCanExecute, _exitCanExecute;

        #region FileCommands
        public static RoutedCommand NewCommand = new RoutedCommand();
        public static RoutedCommand OpenCommand = new RoutedCommand();
        public static RoutedCommand SaveCommand = new RoutedCommand();
        public static RoutedCommand SaveAsCommand = new RoutedCommand();
        public static RoutedCommand CopyCommand = new RoutedCommand();
        public static RoutedCommand PasteCommand = new RoutedCommand();
        public static RoutedCommand CutCommand = new RoutedCommand();
        public static RoutedCommand DeleteCommand = new RoutedCommand();
        public static RoutedCommand ExportCommand = new RoutedCommand();
        public static RoutedCommand WorkshopCommand = new RoutedCommand();
        public static RoutedCommand PrintCommand = new RoutedCommand();
        public static RoutedCommand PrinterCommand = new RoutedCommand();
        public static RoutedCommand ExitCommand = new RoutedCommand();
        #endregion

        public MainMenu(MainWindow parentWindow)
        {
            InitializeComponent();

            try
            {
                mainWindow = parentWindow;

                //FileMenu - new
                _newCanExecute = true;
                //this.CommandBindings.Add(new CommandBinding(NewCommand, NewExecuted, NewCanExecute));
                //file_new.Command = NewCommand;
                //KeyGesture kgNew = new KeyGesture(Key.N, ModifierKeys.Control);
                //this.InputBindings.Add(new InputBinding(NewCommand, kgNew));

                //FileMenu - open
                _openCanExecute = true;
                this.CommandBindings.Add(new CommandBinding(OpenCommand, OpenExecuted, OpenCanExecute));
                file_open.Command = OpenCommand;
                KeyGesture kgOpen = new KeyGesture(Key.O, ModifierKeys.Control);
                file_open.InputGestureText = "Ctrl+O";
                this.InputBindings.Add(new InputBinding(OpenCommand, kgOpen));

                //FileMenu - save
                _saveCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(SaveCommand, SaveExecuted, SaveCanExecute));
                file_save.Command = SaveCommand;
                KeyGesture kgSave = new KeyGesture(Key.S, ModifierKeys.Control);
                file_save.InputGestureText = "Ctrl+S";
                this.InputBindings.Add(new InputBinding(SaveCommand, kgSave));

                //FileMenu - saveAs
                _saveAsCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(SaveAsCommand, SaveAsExecuted, SaveAsCanExecute));
                file_saveAs.Command = SaveAsCommand;

                //FileMenu - copy
                _copyCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(CopyCommand, CopyExecuted, CopyCanExecute));
                file_copy.Command = CopyCommand;
                KeyGesture kgCopy = new KeyGesture(Key.C, ModifierKeys.Control);
                file_copy.InputGestureText = "Ctrl+C";
                this.InputBindings.Add(new InputBinding(CopyCommand, kgCopy));

                //FileMenu - paste
                _pasteCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(PasteCommand, PasteExecuted, PasteCanExecute));
                file_paste.Command = CopyCommand;
                KeyGesture kgPaste = new KeyGesture(Key.V, ModifierKeys.Control);
                file_paste.InputGestureText = "Ctrl+V";
                this.InputBindings.Add(new InputBinding(PasteCommand, kgPaste));

                //FileMenu - cut
                _cutCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(CutCommand, CutExecuted, CutCanExecute));
                file_cut.Command = CutCommand;
                KeyGesture kgCut = new KeyGesture(Key.X, ModifierKeys.Control);
                file_cut.InputGestureText = "Ctrl+X";
                this.InputBindings.Add(new InputBinding(CutCommand, kgCut));

                //FileMenu - delete
                _deleteCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(DeleteCommand, DeleteExecuted, DeleteCanExecute));
                file_delete.Command = DeleteCommand;
                KeyGesture kgDelete = new KeyGesture(Key.Delete, ModifierKeys.Control);
                file_delete.InputGestureText = "Supr";
                this.InputBindings.Add(new InputBinding(DeleteCommand, kgDelete));

                //FileMenu - export
                _exportCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(ExportCommand, ExportExecuted, ExportCanExecute));
                file_export.Command = ExportCommand;
                KeyGesture kgExport = new KeyGesture(Key.E, ModifierKeys.Control);
                file_export.InputGestureText = "Ctrl+E";
                this.InputBindings.Add(new InputBinding(ExportCommand, kgExport));

                //FileMenu - print
                _printCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(PrintCommand, PrintExecuted, PrintCanExecute));
                file_print.Command = WorkshopCommand;

                //FileMenu - printer
                _printerCanExecute = false;
                this.CommandBindings.Add(new CommandBinding(PrinterCommand, PrinterExecuted, PrinterCanExecute));
                file_printer.Command = WorkshopCommand;

                //FileMenu - exit
                _exitCanExecute = true;
                this.CommandBindings.Add(new CommandBinding(ExitCommand, ExitExecuted, ExitCanExecute));
                file_exit.Command = ExitCommand;

                //ElementMenu 
                menu_Element.IsEnabled = false;

                //CategoryMenu
                menu_Category.IsEnabled = false;

                //VotingMenu
                menu_Voting.IsEnabled = false;

                //StructureMenu
                menu_Structure.IsEnabled = false;

                //AnalysisMenu
                menu_Analysis.IsEnabled = false;

                //RecordMenu
                menu_Record.IsEnabled = false;

                //OptionsMenu
                menu_Options.IsEnabled = false;

                this.Focus();

            }

            catch (Exception)
            {
                throw;
            }

        }


        #region File
        public void NewCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _newCanExecute;
            e.Handled = true;
        }

        public void NewExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            mainWindow.CreateNewSession();
            _newCanExecute = true;

            //Falta implementar que te pida guardar la sesion existente antes de abrir una nueva
        }

        private void menu_new_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.CreateNewSession();
        }

        public void OpenCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _openCanExecute;
            e.Handled = true;
        }

        public void OpenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            mainWindow.CreateNewSession();
            _openCanExecute = true;
            //Falta implementar que te pida guardar la sesion existente antes de abrir una nueva
        }

        private void menu_open_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.OpenSession();
        }

        public void SaveCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _saveCanExecute;
            e.Handled = true;
        }

        public void SaveExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _saveCanExecute = !_saveCanExecute;
            //Guardar en cualquier punto
        }

        private void menu_save_Click(object sender, RoutedEventArgs e)
        {

        }

        public void SaveAsCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _saveAsCanExecute;
            e.Handled = true;
        }

        public void SaveAsExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _saveAsCanExecute = !_saveAsCanExecute;
            //Guardar en cualquier punto 
        }

        private void menu_saveAs_Click(object sender, RoutedEventArgs e)
        {

        }

        public void CopyCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _copyCanExecute;
            e.Handled = true;
        }

        public void CopyExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _copyCanExecute = !_copyCanExecute;

        }

        private void menu_copy_Click(object sender, RoutedEventArgs e)
        {

        }

        public void PasteCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _pasteCanExecute;
            e.Handled = true;
        }

        public void PasteExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _pasteCanExecute = !_pasteCanExecute;

        }

        private void menu_paste_Click(object sender, RoutedEventArgs e)
        {

        }

        public void CutCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _cutCanExecute;
            e.Handled = true;
        }

        public void CutExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _cutCanExecute = !_cutCanExecute;

        }

        private void menu_cut_Click(object sender, RoutedEventArgs e)
        {

        }

        public void DeleteCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _deleteCanExecute;
            e.Handled = true;
        }

        public void DeleteExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _deleteCanExecute = !_deleteCanExecute;

        }

        private void menu_delete_Click(object sender, RoutedEventArgs e)
        {

        }

        public void ExportCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _exportCanExecute;
            e.Handled = true;
        }

        public void ExportExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _exportCanExecute = !_exportCanExecute;

        }

        private void menu_export_Click(object sender, RoutedEventArgs e)
        {

        }

        public void PrintCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _printCanExecute;
            e.Handled = true;
        }

        public void PrintExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _printCanExecute = !_printCanExecute;

        }

        private void menu_print_Click(object sender, RoutedEventArgs e)
        {

        }

        public void PrinterCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _printerCanExecute;
            e.Handled = true;
        }

        public void PrinterExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _printerCanExecute = !_printerCanExecute;

        }

        private void menu_printer_Click(object sender, RoutedEventArgs e)
        {

        }

        public void ExitCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = _exitCanExecute;
            e.Handled = true;
        }

        public void ExitExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            _exitCanExecute = !_exitCanExecute;

        }

        private void menu_exit_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.SaveAndCloseApp();
        }

        #endregion

        #region Element

        private void menu_triggering_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.ShowEditTriggeringQuestion();
        }
        
        private void menu_setAType_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_addIdea_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.ShowAddIdeaDialog();
        }

        private void menu_editIdea_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void menu_deleteIdea_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_undeleteIdea_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_compressList_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_renumberList_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_searchByNumber_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_searchByString_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_searchNext_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_selectElements_Click(object sender, RoutedEventArgs e)
        {
        }

        #endregion

        #region Participant
        private void menu_addParticipant_Click(object sender, RoutedEventArgs e)
        {
            //mainWindow.ShowAddParticipantDialog();
        }

        private void menu_editParticipant_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void menu_showParticipants_Click(object sender, RoutedEventArgs e)
        {

        }

        #endregion

        #region Category
        private void menu_genericQuestion_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_categorizingAllElements_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_categorizingSelectedElements_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_categorizingOneElement_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_clear_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_inputNames_Click(object sender, RoutedEventArgs e)
        {
        }

        private void menu_clearNames_Click(object sender, RoutedEventArgs e)
        {
        }

        #endregion

        #region Voting
        #endregion

        #region Structure
        #endregion

        #region Analysis
        #endregion

        #region Record
        #endregion

        #region Options
        #endregion

        #region Help
        
        private void menu_about_Click(object sender, RoutedEventArgs e)
        {
            var aboutDialog = new AboutDialog();
            aboutDialog.ShowDialog();
        }

        #endregion

    }
}
